package org.hhchat.leetcode.string;

import java.util.ArrayList;
import java.util.List;

/**
 * Created this one by HMH on 2017/12/1.
 */
public class code722 {
    static class Solution{
        public List<String> removeComments(String[] source) {

            List<String> result = new ArrayList<>();

            boolean isInComments = false;
            boolean isInBlock = false;
            boolean isInLine = false;

            boolean isNewLine = true;
            StringBuilder sb = new StringBuilder();

            char cur = '#';
            char last = '#';

            for(String str:source){
                for(int i = 0 ; i < str.length(); i++ ){
                    last = cur;
                    cur = str.charAt(i);

                    if(!isInComments){
                        if(last == '/' && cur=='/'){
                            sb.deleteCharAt(sb.length()-1);
                            if(sb.length()!=0)
                                result.add(sb.toString());
                            sb = new StringBuilder();
                            break;
                        }
                        if(last == '/' && cur=='*'){
                            isInComments = true;
                            isInBlock = true;
                            sb.deleteCharAt(sb.length()-1);
                            cur = '#';
                        }else{
                            sb.append(cur);
                            System.out.println(sb.toString());
                        }
                    }else{
                        if(last == '*' && cur=='/'){
                            isInComments = false;
                            isInBlock = false;
                            cur = '#';
                            continue;
                        }
                    }
                }
                if(!isInComments) {
                    if (sb.length() != 0)
                        result.add(sb.toString());
                    sb = new StringBuilder();
                    cur = '#';
                }
                last = '#';
            }
            return result;
        }
    }

    public static void main(String[] args){
        List<String> list = new ArrayList<>();
        list.add("a/*/b//*c");
        list.add("blank");
        list.add("d//*e*//f");
        System.out.println(new Solution().removeComments(list.toArray(new String[0])));
    }

}
